#ifndef __MAIN_HEAD
#define __MAIN_HEAD

#include <iostream>
#include "config.hpp"
#include "platform.hpp"
#include <sys/stat.h>
#include <unistd.h>
#include "app/app.hpp"

extern void register_device(platform* plat,json& fp);
extern cache_mem com;
namespace PLATFORM{
    xilinx xilinx_platform;
    altera altera_platform;
};

//初始化可以随时实时变化
volatile int console_fd_global = STDOUT_FILENO; //终端全局描述符
int platform_log_fd_global; //平台日志文件描述符

inline void init_console(json& fp){
    std::string mode;
    fp.find("console","mode",mode);
    if(mode != "debug")
        close(STDOUT_FILENO); //关闭标准输出流
    
    mode.clear();
    fp.find("console","platformlog",mode);
    if(access(mode.c_str(),F_OK) != 0){ //FIXME: 貌似没有什么作用
        goto CREATE;
    }

CREATE:
    platform_log_fd_global = open(platform_log_fd_global,O_RDWR | O_CREAT);
    if(platform_log_fd_global < 0){
        ERR("platform log open error\n");
        exit(1);
    }
}

inline void init_main_thread(){ //初始化主进程的信号
    
}

#endif